package com.zhang.backend.controller;

import com.zhang.backend.common.response.Result;
import com.zhang.backend.entity.Event;
import com.zhang.backend.service.EventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/events")
public class EventController {

    @Autowired
    private EventService eventService;

    @PostMapping
    public Result<Event> addEvent(@RequestBody Event event) {
        eventService.save(event);
        return Result.success(event);
    }

    @GetMapping("/person/{personId}")
    public Result<List<Event>> getEventsByPersonId(@PathVariable Long personId) {
        List<Event> events = eventService.list(new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<Event>().eq("person_id", personId));
        return Result.success(events);
    }
}
